package com.chesnutconsulting.otbasket.controller;

import com.google.common.collect.Sets;

import java.io.Serializable;
import java.util.List;
import java.util.Set;

/**
 * User: kandhari
 * Date: 3/17/13 11:47 AM
 * <p/>
 * Document me
 */
public class BasketEmailInfo implements Serializable {
    private String toEmail;
    private String fromPersonName;

    private String subject;
    private String additionalMessage;

    private List<AssetIdAndComment> assetIdAndComments;

    public String getToEmail() {
        return toEmail;
    }

    public void setToEmail(String toEmail) {
        this.toEmail = toEmail;
    }

    public String getFromPersonName() {
        return fromPersonName;
    }

    public void setFromPersonName(String fromPersonName) {
        this.fromPersonName = fromPersonName;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public String getAdditionalMessage() {
        if(additionalMessage == null) {
            additionalMessage = String.format("%s has shared these assets with you", fromPersonName);
        }

        return additionalMessage;
    }

    public void setAdditionalMessage(String additionalMessage) {
        this.additionalMessage = additionalMessage;
    }

    public List<AssetIdAndComment> getAssetIdAndComments() {
        return assetIdAndComments;
    }

    public void setAssetIdAndComments(List<AssetIdAndComment> assetIdAndComments) {
        this.assetIdAndComments = assetIdAndComments;
    }

    public Set<String> getAssetIds() {
        Set<String> assetIds = Sets.newHashSet();
        for(AssetIdAndComment ac : getAssetIdAndComments()) {
            assetIds.add(ac.getAssetId());
        }

        return assetIds;
    }

    public String commentForAssetId(String assetId) {
        String comment = null;
        for(AssetIdAndComment ac : getAssetIdAndComments()) {
            if(assetId.equalsIgnoreCase(ac.getAssetId())) {
                comment = ac.getComment();
            }
        }

        return comment;
    }

    public static class AssetIdAndComment {
        private String assetId;
        private String comment;

        public AssetIdAndComment(String assetId, String comment) {
            this.assetId = assetId;
            this.comment = comment;
        }

        public String getAssetId() {
            return assetId;
        }

        public void setAssetId(String assetId) {
            this.assetId = assetId;
        }

        public String getComment() {
            return comment;
        }

        public void setComment(String comment) {
            this.comment = comment;
        }
    }
}
